package com.handpay.zztong.hp.swiper.model.transfer;

import android.content.DialogInterface;

import com.handpay.framework.fastjson.FastJsonHelper;
import com.handpay.zztong.hp.base.activity.ZZTongActivity;
import com.handpay.zztong.hp.base.callback.BusinessEngineListener;
import com.handpay.zztong.hp.base.model.base.BaseModel;
import com.handpay.zztong.hp.bean.Bill;
import com.handpay.zztong.hp.config.HttpUrlConstant;
import com.handpay.zztong.hp.webpay.model.AccountTransfer;

import java.util.Hashtable;

/**
 * Created by lyang on 2017/3/27.
 */

public class TransferModel extends BaseModel {

    private BusinessEngineListener mBusinessEngineListener;
    public boolean doAccountTransferPost(ZZTongActivity activity, Hashtable<String, String> params, BusinessEngineListener listener) {
        mBusinessEngineListener = listener;
        return doPost(activity, HttpUrlConstant.DO_AccountTransfer20, params, true, true);
    }


    public boolean doMarketAccountTransferPost(ZZTongActivity activity, Hashtable<String, String> params, BusinessEngineListener listener) {
        mBusinessEngineListener = listener;
        return doPost(activity,HttpUrlConstant .DO_MarketAccountTransfer, params, true, true);
    }

    public boolean doSubatmTransferPost(ZZTongActivity activity, Hashtable<String, String> params, BusinessEngineListener listener) {
        mBusinessEngineListener = listener;
        return doPost(activity,HttpUrlConstant. Do_SubatmTransfer, params, true, false);
    }


    @Override
    public boolean netResponse(String action, byte[] data) {
        boolean bResult = super.netResponse(action, data, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (mActivity!=null){
                    mActivity.finish();
                }
            }
        });
        if (bResult) {
            return true;
        }
        if (action.equals(HttpUrlConstant.DO_AccountTransfer20)||action.equals(HttpUrlConstant.DO_MarketAccountTransfer)) {
            AccountTransfer bean = null;
            if (data_type == DATA_TYPE.DATA_TYPE_JSON) {
                try {
                    String result = new String(data, "UTF-8");
                    bean = FastJsonHelper.getObject(result, AccountTransfer.class);

                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
            }
            if (mBusinessEngineListener != null) {
                mBusinessEngineListener.callbackBusinessResponse(bean);
            }
        }else if (action.equals(HttpUrlConstant.Do_SubatmTransfer)) {
            AccountTransfer bean = null;
            if (data_type == DATA_TYPE.DATA_TYPE_JSON) {
                try {
                    String result = new String(data, "UTF-8");
                    bean = FastJsonHelper.getObject(result, AccountTransfer.class);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
            }
            if (mBusinessEngineListener != null) {
                mBusinessEngineListener.callbackBusinessResponse(bean);
            }
        }
        return  true;
    }
}
